﻿using System.Net;
using System.Web.Mvc;
using YogaStudio.Data.Domain;
using YogaStudio.Service.BLL;

namespace YogaStudio.WebUI.Controllers
{
    public class SemestersController : Controller
    {
      //  private YogaStudioEntities db = new YogaStudioEntities();
         ISemester  obj=new SemesterService();
        // GET: Semesters
        public ActionResult Index()
        {

            return View(obj.GetAllSemesters());
        }

        // GET: Semesters/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult((int) HttpStatusCode.BadRequest);
            }

            Semester semester = obj.GetSemester((int) id);
            if (semester == null)
            {
                return HttpNotFound();
            }
            return View(semester);
        }

        // GET: Semesters/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: Semesters/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,SemesterName,Description")] Semester semester)
        {
            if (ModelState.IsValid)
            {
                obj.SaveSemeter(semester);
                return RedirectToAction("Index");
            }

            return View(semester);
        }

        // GET: Semesters/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult((int) HttpStatusCode.BadRequest);
            }

            Semester semester = obj.GetSemester((int)id);
            if (semester == null)
            {
                return HttpNotFound();
            }
            return View(semester);
        }

        // POST: Semesters/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "Id,SemesterName,Description")] Semester semester)
        {
            if (ModelState.IsValid)
            {
                obj.UpdateSemester(semester);
             
                return RedirectToAction("Index");
            }
            return View(semester);
        }

        // GET: Semesters/Delete/5
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult((int) HttpStatusCode.BadRequest);
            }
            Semester semester = obj.GetSemester((int)id);
            if (semester == null)
            {
                return HttpNotFound();
            }
            return View(semester);
        }

        // POST: Semesters/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            Semester semester = obj.GetSemester(id);
            obj.DeleteSemeter(semester);
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
               obj.Dispose(true);
            }
            base.Dispose(disposing);
        }
    }
}
